#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
#include<fcntl.h>
#include<stdlib.h>
#define FILENAME "myfifo"

int main()
{
    int fd = open(FILENAME, O_RDWR);
    if(fd < 0){
        perror("open fail!\n");
        exit(-1);
    }

    char msg[128];
    while(1){
        msg[0] = 0;
        printf("please wtire:");
        fflush(stdout);
        //一直刷新缓冲区但是此时缓冲区没有东西
        ssize_t s = read(0, msg, sizeof(msg) -1);
        if(s > 0){
            msg[s-1] = 0; //因为此时msg的结尾是 xxxx\n\0
            write(fd, msg, strlen(msg));
        }

    }
    close(fd);
    return 0;
}